#include "Node.h"
#include <unistd.h>
#include <iostream>
Slave::Slave(socketinf si) {
    this->si = si;
}
void Slave::sendDoki() {
    try {
        this->dataFrame.sendFrame(this->si.socket_fd, PC::CtrlFrameFlag::doki, 0);
    } catch(const Exception& e) {
        localMaster.removeSlave(this);
    }
    
}

void Slave::printInfo(){
    char ip[16];
    this->si.getip(ip);
    std::cout << "IP:" << ip << " port:" << ntohs(this->si.addr.sin_port) << std::endl;
}
Slave::~Slave(){
    std::cout << "Execute close" << std::endl;
    shutdown(this->si.socket_fd, SHUT_RDWR);
    this->si.close();
}